import { HotUpdate, HotMsg } from "./HotUpdate/HotUpdate";

const { ccclass, property } = cc._decorator;


@ccclass
export default class Helloworld extends cc.Component {
    @property(HotUpdate)
    hotNode: HotUpdate = null;
    @property(cc.Label)
    label: cc.Label = null;
    @property(cc.Label)
    msgLabel: cc.Label = null;
    @property(cc.Label)
    versionLabel:cc.Label=null;
    
    private _index = 0;
    private _curr = 0;
    onLoad() {
        this.label.string = `${this._curr}`;
    }
    startHotUpdate() {
        this.hotNode.startListener(this._hotUpdate.bind(this))
        this.hotNode.checkHotUpdate(() => {
            
            this.msgLabel.string = '更新完成'
        })
    }
    _hotUpdate(msg: HotMsg) {
        console.log(msg)
        this.versionLabel.string =  `版本号:${msg.version}`;
        this.msgLabel.string = msg.info
    }
    update(dt: number) {
        if (this._index <= 1) {
            this._index += dt;
        } else {
            this._curr++;
            this._index = 0;
            this.label.string = `${this._curr}`;

        }
    }
}
